﻿using In66.Net.Core.System.Extensions.Expressions;
using In66.Net.Repository.IRepositories.ISqlSugar;

namespace Maint.Api.Services.Impl;

public class NoticeAppService : AbstractAppService, INoticeAppService
{
    private readonly ISugarBaseRepository<Notice> _noticeRepository;

    public NoticeAppService(ISugarBaseRepository<Notice> noticeRepository)
    {
        _noticeRepository = noticeRepository;
    }

    public async Task<AppSrvResult<List<NoticeVo>>> GetListAsync(NoticeSearchDto search)
    {
        search.TrimStringFields();

        var whereCondition = ExpressionCreator
                                            .New<Notice>()
                                            .AndIf(!string.IsNullOrWhiteSpace(search.Title), x => x.Title == search.Title);

        var notices = _noticeRepository.QueryListByClause(whereCondition)
                                        .ToList();

        return Mapper.Map<List<NoticeVo>>(notices);
    }
}